/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.binkam.merashehar.dao;

import com.binkam.merashehar.common.database.MSHibernateUtil;
import com.binkam.merashehar.dto.Infoitem;
import com.binkam.merashehar.dto.Subcategory;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author binkam
 */
public class ItemDAO {
    public List findItems(Subcategory s, int pageNo, int rowsPerPage) {
        String sql = "select i from Infoitem as i , Subcategory as s where i.subcategory.subcategoryid=s.subcategoryid and s.subcategoryid = "+s.getSubcategoryid().intValue();
        Session session = MSHibernateUtil.getSessionFactory().openSession();
        Query query = session.createQuery(sql);
        query.setMaxResults(rowsPerPage);
        query.setFirstResult(pageNo);
        List catList = query.list();
        return catList;
    }

    public static void main(String[] args) {
        
        ItemDAO itemDAO = new ItemDAO();
        Subcategory s = new Subcategory();
        s.setSubcategoryid(10);
        List infoList = itemDAO.findItems(s,11,10);
        for (int i = 0; i < infoList.size(); i++) {
            Infoitem item = ((Infoitem)infoList.get(i));
            System.out.println("item"+item.getItemname());
        }
    }
}
